<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        #test{
            width:100px;
            height: 100px;
            
        }
    </style>
</head>

<body>
    <div id="test" style="background: #abcdef;"></div>
    <script>
        // try{
        //     //如果try语句错误，就会执行catch中的语句，若没有则不执行
        //     alert(10)
        // }
        // catch(err){
        //     // alert(10);
        //     console.log(err.message)
        // }
        // bg = getComputedStyle(test).backgroundColor;
        // alert(bg);
        // var bg = test.currentStyle.backgroundColor;
        // alert(bg);
        try {
            //chrome
            bg = getComputedStyle(test).backgroundColor;
            console.log(bg);
        }
        catch (err) {
            //IE
            bg = test.currentStyle.backgroundColor;
            alert(bg);
        }
    </script>
</body>

</html>